/**
* Created by alan on 17-5-8.
*/
<template>
  <section>
    <el-form ref="form" label-width="140px" id='cashForm'>
      <el-form-item label="设定状态 ">
        <el-switch
          v-model="loanSwitch"
          @change="setSwitchLimit()"
          active-color="#13ce66"
          inactive-color="#ff4949">
        </el-switch>
      </el-form-item>
      <el-form-item label="今日放款限额">
        {{cashNum}}
      </el-form-item>
      <el-form-item label="金额设定（万）">
        <el-input style="width: 120px" v-model="cashValue"></el-input> 
      </el-form-item>
      <!-- <el-form-item> -->
        <el-button type="primary" id="premaryBtn"  @click="setCashLimit()">设定</el-button>
      <!-- </el-form-item> -->
    </el-form>
  </section>
</template>
<script>
  import DataUtil from '../../common/dataUtil'
  export default {
    data () {
      return {
        cashNum:'',
        cashValue:'',
        loanSwitch: true,
      }
    },
    methods: {
// 设置值
// manage/redisStringValueEdit
// 放款开关 key loan:off:no   value 0 关,1 开
// 当日最大放款量 key loan:omniaccount:sys:day:total:account   value 单位元

// 查询值
// manage/redisStringValue
// 放款开关 key loan:off:no   value 0 关,1 开
// 当日最大放款量 key loan:omniaccount:sys:day:total:account   value 单位元
      setSwitchLimit() {
        let _loanSwitch;
          if(this.loanSwitch==true){
            _loanSwitch=1
          }else {
            _loanSwitch=0
          }
          this.$http.post('manage/redisStringValueEdit',{"key":"loan:off:no","value":_loanSwitch}).then(response=>{
            let {body} = response;
            if (1 == body.code) {
              this.$message(body.message);
            } else {
              this.$message.error(body.message);
            }
          },response=>{});

        
      },
      setCashLimit() {
        this.$http.post('manage/redisStringValueEdit',{"key":"loan:omniaccount:sys:day:total:account","value":this.cashValue}).then(response=>{
          let {body} = response;
          if (1 == body.code) {
            this.$message(body.message);
            this.cashNum=this.cashValue;
            this.cashValue="";
          } else {
            this.$message.error(body.message);
          }
        },response=>{});
      },
      bindGrid() {
        this.$http.post('manage/redisStringValue', {"key":"loan:omniaccount:sys:day:total:account"}).then(response => {
          let {body} = response;
          if (1 == body.code) {
            this.cashNum=body.data["value"];
          } else {
            this.$message.error(body.message);
          }
        }).catch((e) =>{
          // this.gridLoading = false;
        })
        this.$http.post('manage/redisStringValue', {"key":"loan:off:no"}).then(response => {
          let {body} = response;
          if (1 == body.code) {
            if(body.data["value"]==1){
              this.loanSwitch=true;
            }else {
              this.loanSwitch=false;
            }
          } else {
            this.$message.error(body.message);
          }
        }).catch((e) =>{
          // this.gridLoading = false;
        })
      }
    },
    mounted: function () {
      this.bindGrid();
    }
  }
</script>
<style>
  #cashForm {
    padding: 40px 0;
    font-weight: 700;
  }
  #premaryBtn {
    margin-left: 50px;
    width: 80px;
  }
</style>
